﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Bidder_TraPurList : System.Web.UI.Page
{
    private string PPProjectId = "", Accountid="",Goodsid="";
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
       if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
           HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
           if (_Account != null)
           {
               PPProjectId = SysFun.IsSQL(SysFun.ToName2(Request.QueryString["ProjectId"]));
               Goodsid = SysFun.IsSQL(SysFun.ToName2(Request.QueryString["goodsid"]));
               Accountid = _Account.AccountId.ToString();
               if (_Account.Sort == "0") //生产企业
               {
                   showGridView(0);
               }
               else if (_Account.Sort == "1") //经营企业
               {
                   showGridView(1);
               }
           }
           
        }
    }
    private void showGridView(int sort)
    {
        
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = " PurchaseTable";                                               //要查询的表明
        dbPage.Key = "hspid";                                               //表的主键    
        dbPage.Where = fctConditions(sort);                                           //查询条件    
        dbPage.SelectField = " CompanyName_TB,GoodsId,ProductName,GoodsName,MedicineModel,Outlookc,Factor,IsNull(Unit,'')+'/'+IsNull(PackUnit,'') As Pack1,CASE QualityLevels " + ConfigurationManager.AppSettings["QualityLevels"].ToString() + " END AS QualityLevels,PurchasePrice,accountid_sc,UserCode_SC,CompanyName_SC,CompanyName_TB,UserCode_TB,HospitalName,accountid_ps,UserCode_PS,CompanyName_PS,BidPrice,PlanPurNum,convert(numeric(30,2),PurchasePrice*PlanPurNum) as PlanPrice ";
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 3;                                                    //显示记录条数   
        if (sort == 0)
        {
            dbPage.OrderBy = "HospitalName,UserCode_SC,GoodsId,Medicinemodel";                  //排序字段
        }
        else
        {
            dbPage.OrderBy = "HospitalName,UserCode_PS,GoodsId,MedicineModel";                  //排序字段
        }
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }
    private string fctConditions(int sort)
    {
        string strtemp;
        if (sort == 0)
        {
            strtemp = "  projectid=" + PPProjectId + " and AccountId_SC=" + Accountid + " And State='正常采购' and supplygoodsid=" + Goodsid + " and";
        }
        else
        {
            strtemp = "  projectid=" + PPProjectId + " and  Accountid_TB=" + Accountid + " And State='正常采购' And supplygoodsid="+Goodsid+" and";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }

        return strtemp;

    }

}
